using UnityEngine;
using System.Collections;

public class AnimatedModel : MonoBehaviour {
	
	public string animationName;
	public float speedFactor = 1.0f;
	private bool animationEnabled;
	// Use this for initialization
	void Start ()
	{
		startAnimation();
	}
	public void setAnimationName(string name)
	{
		animationName = name;
		startAnimation();
	}
	public void setAnimationEnabled(bool e)
	{
		animationEnabled = e;
		if(e)
			startAnimation();
	}
	private void startAnimation()
	{
		if(animationName != null && animationName != "")
		{
			AnimationState walk = gameObject.animation[animationName];
	        walk.enabled = true;
	        walk.wrapMode = WrapMode.Loop;
		}
	}
	public bool isAnimationEnabled()
	{
		return animationEnabled;
	}
	// Update is called once per frame
	public void Update ()
	{
		AnimationState walk = gameObject.animation[animationName];
		if(walk != null) //TODO remove
		{
			if (animationEnabled)
	            walk.speed = 0.5f * speedFactor;
	        else
	            walk.speed = 0.05f * speedFactor;
		}
	}
}
